package com.bocloud.cmp.driver.providers.impl;

import org.springframework.stereotype.Service;

import com.bocloud.cmp.driver.config.Configuration;
import com.bocloud.cmp.driver.providers.MonitorDriver;
import com.bocloud.cmp.driver.providers.intf.MonitorProvider;
import com.bocloud.cmp.driver.providers.vmware.VmwareMonitorDriver;
import com.bocloud.cmp.driver.utils.VendorConverter;
import com.bocloud.cmp.enums.VendorType;
import com.bocloud.cmp.model.Butler;
import com.bocloud.common.model.BsmResult;

/**
 * 性能数据服务接口实现类
 * 
 * @author weiwei
 *
 */
@Service("monitorProvider")
public class MonitorProviderImpl implements MonitorProvider {

	@Override
	public BsmResult query(String vendor, String name, String category, String type, String time) {
		MonitorDriver driver = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType vendorType = VendorConverter.convert(butler.getCategory());
		switch (vendorType) {
		case VMWARE:
			driver = new VmwareMonitorDriver(butler.getUrl(), butler.getUsername(), butler.getPassword());
			break;
		case OPENSTACK:

			break;
		default:
			break;
		}
		if (null == driver) {
			return new BsmResult(false, "暂不支持");
		} else if (!driver.accessable()) {
			return new BsmResult(false, "用户鉴权失败");
		} else {
			return driver.query(time, name, category, type);
		}
	}

}
